package com.example.accessingdatajpa.controller;

import com.example.accessingdatajpa.pojo.LiveBroadcast;
import com.example.accessingdatajpa.response.RestResponse;
import com.example.accessingdatajpa.service.ILiveBroadcastService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app")
public class LiveBroadcastController {
    @Autowired
    final private ILiveBroadcastService liveBroadcastService;

    public LiveBroadcastController(ILiveBroadcastService liveBroadcastService) {
        this.liveBroadcastService = liveBroadcastService;
    }

    //get all
    @GetMapping(path = "/live-get-all")
    public @ResponseBody RestResponse<List<LiveBroadcast>> getAllUp(){
        return liveBroadcastService.queryAllLiveBroadcast();
    }

    //add
    @PostMapping(path = "/live-add-new")
    public @ResponseBody RestResponse<String> addOneUp(@RequestBody LiveBroadcast liveBroadcast){
        return liveBroadcastService.addNewUp(liveBroadcast);
    }

    //update
    @PutMapping(path = "/live-update/{id}")
    public @ResponseBody RestResponse<String> updateOneUp(@RequestParam("id") Long id,@RequestBody LiveBroadcast liveBroadcast){
        return liveBroadcastService.updateUp(id, liveBroadcast);
    }

    //delete
    @DeleteMapping(path = "/live-delete/{id}")
    public @ResponseBody RestResponse<String> deleteOneUp(@RequestParam("id") Long id){
        return liveBroadcastService.deleteUp(id);
    }
}
